package com.igeek.ch02.controller;

import com.igeek.ch02.common.CommonResult;
import com.igeek.ch02.service.UserService;
import com.igeek.ch02.utils.JSONUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet(name = "UserDeleteServlet",urlPatterns = "/userDelete")
public class UserDeleteServlet extends HttpServlet {

    UserService userService=new UserService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        int id =Integer.parseInt(request.getParameter("id")) ;

        boolean flag =userService.delete(id);
        CommonResult commonResult=null;
        if (flag){
            commonResult=new CommonResult(200,"删除成功",flag);
        }else {
            commonResult=new CommonResult(200,"删除成功",flag);
        }

        JSONUtils.writeJson(response,commonResult);
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        this.doPost(request, response);
    }
}
